#include "stdafx.h"
#include "RTCamera.h"

RTCamera::RTCamera()
{
	m_vLook = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
	m_vUp = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
	m_vPosition = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );

	D3DXMatrixIdentity( &m_matView );
	D3DXMatrixIdentity( &m_matTrans );
	D3DXMatrixIdentity( &m_matRotation );
}

RTCamera::~RTCamera()
{

}

BOOL	RTCamera::Create( LPDIRECT3DDEVICE9 pDevice )
{
	D3DXMATRIX matProjection;
	D3DXMatrixPerspectiveFovLH( &matProjection, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f );
	pDevice->SetTransform( D3DTS_PROJECTION, &matProjection );

	return TRUE;
}

BOOL	RTCamera::Update( LPDIRECT3DDEVICE9 pDevice )
{
	D3DXMatrixLookAtLH( &m_matView, &m_vPosition, &m_vLook, &m_vUp );
	m_matView = m_matTrans * m_matView;
	pDevice->SetTransform( D3DTS_VIEW, &m_matView );

	return TRUE;
}

void	RTCamera::SetPosition( float x, float y, float z )
{
	m_vPosition.x = x;
	m_vPosition.y = y;
	m_vPosition.z = z;
}

void	RTCamera::SetLookAt( float x, float y, float z )
{
	m_vLook.x = x;
	m_vLook.y = y;
	m_vLook.z = z;
}

void	RTCamera::SetUpVector( D3DXVECTOR3* vUp )
{
	m_vUp = *vUp;
}

void	RTCamera::Rotation( float angle )
{
	D3DXMatrixRotationY( &m_matRotation, angle );
}

void	RTCamera::Translation( float x, float y, float z )
{
	D3DXMatrixTranslation( &m_matTrans, x, y, z );
}
